
# Exception 是所有异常的超类、自定义异常继承（ErrorValue）、raise 抛异常 、finally


# 自定义异常类
class MyException(Exception):

    def __init__(self, msg):
        self.msg = msg


# raise 抛出异常
def division(x, y):
    if y == 0:
        raise MyException('除数不能为0')
    return x / y


if __name__ == '__main__':

    # try 、catch、finally做异常处理。

    try:
        print(division(1, 2))
        print(division(2, 0))
    except ValueError as ve:
        print(ve)
    except MyException as ve:
        print(ve.msg)
    except Exception as e:
        print("未定义异常", e)
    finally:
        print('执行完成')